/**
 * Created by three on 14-11-4.
 */
'use strict';
(function (app) {

    app.directive('widgetGrid', function () {
        return {
            restrict: 'AE',
            link: function (scope, element, attrs) {
                scope.setup_widget_desktop = function () {
                    if ($.fn.jarvisWidgets && $.enableJarvisWidgets) {
                        element.jarvisWidgets({
                            grid: 'article',
                            widgets: '.jarviswidget',
                            localStorage: true,
                            deleteSettingsKey: '#deletesettingskey-options',
                            settingsKeyLabel: 'Reset settings?',
                            deletePositionKey: '#deletepositionkey-options',
                            positionKeyLabel: 'Reset position?',
                            sortable: true,
                            buttonsHidden: false,
                            // toggle button
                            toggleButton: true,
                            toggleClass: 'fa fa-minus | fa fa-plus',
                            toggleSpeed: 200,
                            onToggle: function () {
                            },
                            // delete btn
                            deleteButton: true,
                            deleteClass: 'fa fa-times',
                            deleteSpeed: 200,
                            onDelete: function () {
                            },
                            // edit btn
                            editButton: true,
                            editPlaceholder: '.jarviswidget-editbox',
                            editClass: 'fa fa-cog | fa fa-save',
                            editSpeed: 200,
                            onEdit: function () {
                            },
                            // color button
                            colorButton: true,
                            // full screen
                            fullscreenButton: true,
                            fullscreenClass: 'fa fa-expand | fa fa-compress',
                            fullscreenDiff: 3,
                            onFullscreen: function () {
                            },
                            // custom btn
                            customButton: false,
                            customClass: 'folder-10 | next-10',
                            customStart: function () {
                                alert('Hello you, this is a custom button...');
                            },
                            customEnd: function () {
                                alert('bye, till next time...');
                            },
                            // order
                            buttonOrder: '%refresh% %custom% %edit% %toggle% %fullscreen% %delete%',
                            opacity: 1.0,
                            dragHandle: '> header',
                            placeholderClass: 'jarviswidget-placeholder',
                            indicator: true,
                            indicatorTime: 600,
                            ajax: true,
                            timestampPlaceholder: '.jarviswidget-timestamp',
                            timestampFormat: 'Last update: %m%/%d%/%y% %h%:%i%:%s%',
                            refreshButton: true,
                            refreshButtonClass: 'fa fa-refresh',
                            labelError: 'Sorry but there was a error:',
                            labelUpdated: 'Last Update:',
                            labelRefresh: 'Refresh',
                            labelDelete: 'Delete widget:',
                            afterLoad: function () {
                            },
                            rtl: false, // best not to toggle this!
                            onChange: function () {

                            },
                            onSave: function () {

                            },
                            ajaxnav: $.navAsAjax // declears how the localstorage should be saved (HTML or AJAX page)

                        });
                    }
                }

                scope.setup_widget_mobile = function () {
                    if ($.enableMobileWidgets && $.enableJarvisWidgets) {
                        scope.setup_widgets_desktop();
                    }
                }

                if ($.device === "desktop") {
                    scope.setup_widget_desktop();
                } else {
                    scope.setup_widget_mobile();
                }

            }
        }
    })

        .directive('widget', function () {
            return {
                restrict: 'AE',
                transclude: true,
                replace: true,
                template: '<div class="jarviswidget" data-ng-transclude=""></div>'
            }
        })

        .directive('widgetHeader', function () {
            return {
                restrict: 'AE',
                transclude: true,
                replace: true,
                scope: {
                    title: '@',
                    icon: '@'
                },
                template: '\
				<header>\
					<span class="widget-icon"> <i data-ng-class="icon"></i> </span>\
					<h2>{{ title }}</h2>\
					<span data-ng-transclude></span>\
				</header>'
            }
        })

        .directive('widgetToolbar', function () {
            return {
                restrict: 'AE',
                transclude: true,
                replace: true,
                template: '<div class="widget-toolbar" data-ng-transclude=""></div>'
            }
        })

        .directive('widgetEditbox', function () {
            return {
                restrict: 'AE',
                transclude: true,
                replace: true,
                template: '<div class="jarviswidget-editbox" data-ng-transclude=""></div>'
            }
        })

        .directive('widgetBody', function () {
            return {
                restrict: 'AE',
                transclude: true,
                replace: true,
                template: '<div data-ng-transclude=""></div>'
            }
        })

        .directive('widgetBodyToolbar', function () {
            return {
                restrict: 'AE',
                transclude: true,
                replace: true,
                scope: {
                    class: '@'
                },
                template: '<div class="widget-body-toolbar" data-ng-transclude=""></div>'
            }
        })

        .directive('widgetContent', function () {
            return {
                restrict: 'AE',
                transclude: true,
                replace: true,
                template: '<div class="widget-body" data-ng-transclude=""></div>'
            }
        })
    ;
}(app));
